

<html>
<body>

<h1><?php print "Enter a query"; ?></h1>

<form action="query.php" method="POST">
<textarea name="query" rows=5 cols=40></textarea>
<input type="submit">
</form>

<h2><?php print "Result: "; ?></h2>

<?php

error_reporting(0);

$db_connection = mysql_connect("localhost", "cs143", "");
mysql_select_db("CS143", $db_connection);

$query = $_POST["query"];

$result = mysql_query($query, $db_connection);
$num_col = mysql_num_fields($result);

set_time_limit(0);
echo "<table border ='1'>";
echo "<tr>";
for($j=0;$j<$num_col;$j++)
{
   $fieldname = mysql_field_name($result, $j);
   echo "<th>";
   print "$fieldname";
   echo "</th>";
}

echo "</tr>";
while($row = mysql_fetch_row($result))
{
   echo "<tr>";
   for($i=0;$i<$num_col;$i++)
   {
      echo "<td>";
      print"$row[$i]";
      echo "</td>";
   }
   echo "</tr>";
}

echo "</table>";
mysql_close($db_connection);

?>


</body>
</html>